import { ApiProperty } from '@nestjs/swagger';
import { Exclude, Expose, Transform, Type } from 'class-transformer';
import { NotificationType, SourceType } from '../../../entities/notification.entity';

/**
 * 精简的用户信息DTO，仅用于通知响应
 */
class UserInfo {
  @ApiProperty({ description: '用户ID' })
  id: string;

  @ApiProperty({ description: '用户名' })
  username: string;

  @ApiProperty({ description: '用户邮箱' })
  email: string;

  @ApiProperty({ description: '用户头像URL', required: false })
  avatar?: string;
}

/**
 * 通知响应DTO
 */
@Exclude()
export class NotificationResponseDto {
  @Expose()
  @ApiProperty({ description: '通知ID' })
  id: string;

  @Expose()
  @ApiProperty({ description: '通知标题' })
  title: string;

  @Expose()
  @ApiProperty({ description: '通知内容' })
  content: string;

  @Expose()
  @ApiProperty({ 
    description: '通知类型',
    enum: NotificationType
  })
  type: NotificationType;

  @Expose()
  @ApiProperty({ description: '接收通知的用户ID' })
  userId: string;

  @Expose()
  @Type(() => UserInfo)
  @ApiProperty({ description: '用户信息', type: UserInfo })
  user: UserInfo;

  @Expose()
  @ApiProperty({ description: '触发通知的源对象ID' })
  sourceId: string;

  @Expose()
  @ApiProperty({ 
    description: '源对象类型',
    enum: SourceType 
  })
  sourceType: SourceType;

  @Expose()
  @ApiProperty({ description: '是否已读' })
  isRead: boolean;

  @Expose()
  @ApiProperty({ description: '创建时间' })
  @Transform(({ value }) => value && new Date(value).toISOString())
  createdAt: Date;

  @Expose()
  @ApiProperty({ description: '更新时间' })
  @Transform(({ value }) => value && new Date(value).toISOString())
  updatedAt: Date;
} 